//
//  MCHongBaoPersonTableViewCell.m
//  XDYL
//
//  Created by menhao on 2018/3/22.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCHongBaoPersonTableViewCell.h"

@interface MCHongBaoPersonTableViewCell()
@property (nonatomic,strong) UIImageView *imagev;
@end

@implementation MCHongBaoPersonTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
         [self setUpUI];
    }
    return self;
}
- (void)setUpUI{
    
    UILabel *textLabel = [[UILabel alloc] init];
    textLabel.textAlignment =NSTextAlignmentCenter;
    textLabel.textColor = RGB(68, 68, 68);
    textLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(14)];
    [self.contentView addSubview:textLabel];
    textLabel.text = @"";
    UIImageView *imagev = [[UIImageView alloc] init];
    [self.contentView addSubview:imagev];
    self.imageV =imagev;
    imagev.image = [UIImage imageNamed:@"gd"];
    UIButton *btn = [[UIButton alloc] init];
    [self.contentView addSubview:btn];
    [btn setBackgroundImage:[UIImage imageNamed:@"hongbaowxz"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"hongbaoxz"] forState:UIControlStateSelected];
    

    self.textMyLabel = textLabel;
    self.btn = btn;
    self.imagev = imagev;
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(MC_REALVALUE(40));
        make.top.equalTo(self.contentView).with.offset(MC_REALVALUE(13));
        make.centerY.equalTo(self.contentView);
    }];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(textLabel);
        make.height.width.equalTo(@(MC_REALVALUE(20)));
        make.right.equalTo(self.contentView.mas_right).offset(MC_REALVALUE(-30));
    }];
    [imagev mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(MC_REALVALUE(-10));
        make.height.equalTo(@(MC_REALVALUE(14)));
        make.width.equalTo(@(MC_REALVALUE(8)));
    }];
}

- (void)setDataSource:(MCPersonHongBaoModel *)dataSource{
    _dataSource = dataSource;
    if (self.isSelf) {
        [self.textMyLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(MC_REALVALUE(26));
            make.top.equalTo(self.contentView).with.offset(MC_REALVALUE(13));
            make.centerY.equalTo(self.contentView);
        }];
    }else{
        [self.textMyLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(MC_REALVALUE(40));
            make.top.equalTo(self.contentView).with.offset(MC_REALVALUE(13));
            make.centerY.equalTo(self.contentView);
        }];
    }
    self.btn.selected = dataSource.selected;
    if (dataSource.selected) {
        self.textMyLabel.textColor = RGB(255, 69, 69);
        
    } else {
        self.textMyLabel.textColor = RGB(68, 68, 68);
    }
    self.textMyLabel.text = dataSource.ChildUserName;
}


- (void)setDataSourceName:(NSString *)dataSourceName{
    _dataSourceName = dataSourceName;
    self.btn.hidden = YES;
    self.imageV.hidden = YES;
    self.textMyLabel.text = dataSourceName;
}

- (void)btnClick:(UIButton *)btn{
    if (self.type == 3) {
        return;
    }

    btn.selected = !btn.selected;
    self.dataSource.selected = btn.selected;
    if (btn.selected) {
        self.textMyLabel.textColor = RGB(255, 69, 69);
        if (self.selectedPersonBlock) {
            self.selectedPersonBlock(self.dataSource);
        }
    } else {
        self.textMyLabel.textColor = RGB(68, 68, 68);
        if (self.unSelectedPersonBlock) {
            self.unSelectedPersonBlock(self.dataSource);
        }
    }
}
@end
